{ include file="../Common/head_authority.html" }
<body>
<div class="container-fluid">
    <div class="row" style="margin: 20px 0px;">
        <b>编辑权限</b>
        <a href="javascript:history.back();" style="float: right;">返回</a>
    </div>
    <form action="#" method="post">
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>菜单等级</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <select id="level" name="level" class="form-control">
                    {if $oldData.level eq 0}
                    <option value="0" selected>一级菜单</option>
                    {else}
                    <option value="0">一级菜单</option>
                    {/if}
                    {if $oldData.level eq 1}
                    <option value="1" selected>二级菜单</option>
                    {else}
                    <option value="1">二级菜单</option>
                    {/if}
                    {if $oldData.level eq 2}
                    <option value="2" selected>三级菜单</option>
                    {else}
                    <option value="2">三级菜单</option>
                    {/if}
                </select>
            </div>
        </div>
        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>权限标题</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="title" class="form-control" value="{$oldData.title}"/>
            </div>
        </div>
        {if $oldData.level eq 0}
        <div class="row" id="icon_box" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>图标类</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="icon_class" class="form-control" value="{$oldData.icon_class}"/>
            </div>
        </div>
        {/if}
        {if $oldData.level eq 1 || $oldData.level eq 2}
        <div class="row" id="parent_box" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>父级菜单</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <select id="parent_id" name="parent_id" class="form-control">
                    {foreach from="$parentMenu" item="v"}
                        {if $oldData.parent_id eq $v.id}
                        <option value="{$v.id}" selected>{$v.title}</option>
                        {else}
                        <option value="{$v.id}">{$v.title}</option>
                        {/if}
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="row" id="control_box" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>控制器名</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="control" class="form-control" value="{$oldData.control}"/>
            </div>
        </div>
        <div class="row" id="method_box" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
                <b>方法名</b>
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <input type="text" name="method" class="form-control" value="{$oldData.method}"/>
            </div>
        </div>
        {/if}

        <div class="row" style="height: 35px;line-height: 35px;margin-top: 15px;">
            <div class="col-sm-2 col-md-2 col-lg-2" style="text-align: right">
            </div>
            <div class="col-sm-5 col-md-5 col-lg-5">
                <button type="submit" class="btn btn-primary pull-right">确定</button>
            </div>
        </div>
    </form>
</body>
{literal}
<script>
    $(document).ready(function(){
        $("#level").change(function(){
            var level = $("#level option:selected").val();
            if(level == 1 || level == 2){
                $("#icon_box").css("display","none");
                $("#icon_box").attr("disabled");
                $("#parent_box,#control_box,#method_box").removeAttr("disabled");
                $("#parent_box,#control_box,#method_box").css("display","block");
                $.ajax({
                    type:'post',
                    url:'./admin.php?c=Authority&m=getParentsIdByLevel',
                    data:{level:level},
                    dataType:'json',
                    success:function(data){
                        var html = "";
                        for(var i=0; i<data.length; i++){
                            html += " <option value='"+data[i].id+"'>"+data[i].title+"</option>";
                        }
                        $("#parent_id").html(html);
                    }
                })
            }
            if(level == 0){
                $("#icon_box").css("display","block");
                $("#icon_box").removeAttr("disabled");
                $("#parent_box,#control_box,#method_box").attr("disabled");
                $("#parent_box,#control_box,#method_box").css("display","none");
            }
        })
    })
</script>
{/literal}
</html>